package com.yunao.service.report.esou;

import com.yunao.commons.serachcore.core.bean.Article;
import com.yunao.commons.serachcore.core.bean.Clusters;
import com.yunao.service.report.Convert;

import com.yunao.service.report.bean.GroupBean;
import com.yunao.service.report.bean.SearchBeans;
import com.yunao.service.report.esou.common.Profile;

public class ReportHtml {

	/**
	 * 报告头部
	 * 
	 * @param title
	 *            标题
	 * @param number
	 *            编号
	 * @param subtitleLeft
	 *            副标题（左）
	 * @param subtitleRight
	 *            副标题（右）
	 * @return 报告头部 html
	 */
	public String createHead(String title, String number, String subtitleLeft, String subtitleRight) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"header\">");
		html.append("<h3 class=\"title\">" + title + "</h3>");
		html.append("<div class=\"number\">" + number + "</div>");
		html.append("<div class=\"subtitle\">");
		html.append("<span class=\"left\">" + subtitleLeft + "</span>");
		html.append("<span class=\"right\">" + subtitleRight + "</span>");
		html.append("</div>");
		html.append("</div>");
		return html.toString();
	}

	/**
	 * 大数据综述
	 * 
	 * @param desc
	 *            大数据综述
	 * @param imgs
	 *            大数据趋势图，多个图片以“,”分隔
	 * @return 大数据综述 html
	 */
	public String createOverview(String nav, String desc, String imgs) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"overview\">");
		html.append("<div class=\"nav\">" + nav + "</div>");
		html.append("<div class=\"desc\">" + desc + "</div>");
		String[] imgArr = Convert.split(imgs, ",");
		if(imgs!=null){
			for (String img : imgArr) {
				if(!img.equals("null"))
					img = img.substring(img.indexOf("export"));
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + img + "\" width=\"600\" height=\"213\" /></div>");
			}
		}
		html.append("</div>");
		return html.toString();
	}
	public String createOverviewM(String nav, String desc,String desc1,String desc2, String desc3,String imgs) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"overview\">");
		html.append("<div class=\"nav\">" + nav + "</div>");
		html.append("<div class=\"desc\">" + desc + "</div>");
		String[] imgArr = Convert.split(imgs, ",");
		for (int i = 0; i < imgArr.length; i++) {
			if(!imgArr[i].equals("null"))
				imgArr[i] = imgArr[i].substring(imgArr[i].indexOf("export"));
			if(i==0){
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
				html.append("<div class=\"desc\">" + desc1 + "</div>");
			}if(i==1){
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
				html.append("<div class=\"desc\">" + desc2 + "</div>");
			}if(i==2){
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
				html.append("<div class=\"desc\">" + desc3 + "</div>");
			}
		}
//		for (String img : imgArr) {
//			if(!img.equals("null"))
//			img = img.substring(img.indexOf("export"));
//			html.append("<div class=\"img\"><img alt=\"\" src=\"" + img + "\" width=\"600\" height=\"213\" /></div>");
//		}
		html.append("</div>");
		return html.toString();
	}
	public String createOverviewW(String nav, String desc,String desc1,String desc2, String imgs) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"overview\">");
		html.append("<div class=\"nav\">" + nav + "</div>");
		html.append("<div class=\"desc\">" + desc + "</div>");
		String[] imgArr = Convert.split(imgs, ",");
		for (int i = 0; i < imgArr.length; i++) {
			if(!imgArr[i].equals("null"))
				imgArr[i] = imgArr[i].substring(imgArr[i].indexOf("export"));
			if(i==0){
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
				html.append("<div class=\"desc\">" + desc1 + "</div>");
			}if(i==3){
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
				html.append("<div class=\"desc\">" + desc2 + "</div>");
			}else{
				if(i!=0)
				html.append("<div class=\"img\"><img alt=\"\" src=\"" + imgArr[i] + "\" width=\"600\" height=\"213\" /></div>");
			}
		
		}
//		for (String img : imgArr) {
//			if(!img.equals("null"))
//			img = img.substring(img.indexOf("export"));
//			html.append("<div class=\"img\"><img alt=\"\" src=\"" + img + "\" width=\"600\" height=\"213\" /></div>");
//		}
		html.append("</div>");
		return html.toString();
	}
	/**
	 * 大数据快讯
	 * 
	 * @param beans
	 *            热点大数据
	 * @return 大数据快讯 html
	 */
	public String createNews(String nav, SearchBeans beans) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"news\">");
		html.append("<div class=\"nav\">" + nav + "</div>");
		html.append("<ul>");
		for (int i = 0; i < beans.size(); i++) {
			html.append("<li><a>" + (i + 1) + ". " + beans.get(i).getTi().replaceAll("<[/]?em>", "") + "</a></li>");
		}
		html.append("</ul>");
		html.append("</div>");
		return html.toString();
	}

	/**
	 * 大数据分布
	 * 
	 * @param imgs
	 *            大数据分布图
	 * @return 大数据分布 html
	 */
	public String createPie(String nav, String imgs) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"pie\">");		
		html.append("<table cellpadding=\"0\" cellspacing=\"0\" style=\"margin: 0 auto;\" width=\"600\">");
		html.append("<tr>");
		String[] imgArr = Convert.split(imgs, ",");
		for (String img : imgArr) {
			img = img.substring(img.indexOf("export"));
			html.append("<td width=\"300\" align=\"center\"><img alt=\"\" src=\"" + img
					+ "\" width=\"267\" height=\"200\"></td>");
		}
		html.append("</tr>");
		html.append("</table>");
		html.append("</div>");
		return html.toString();
	}

	/**
	 * 热点大数据
	 * 
	 * @param beans
	 *            热点大数据
	 * @return 热点大数据 html
	 */
	public String createInfo(String nav, Clusters beans) {
		StringBuilder html = new StringBuilder();
		html.append("<div class=\"info\">");
		html.append("<div class=\"nav\">" + nav + "</div>");
		html.append("<ul>");
		int num = 0;
		if (beans!=null){
			for (int i = 0; i < beans.getData().size(); i++) {
				Article bean = beans.getData().get(i).getDocs().get(0);
				if(bean!=null&&!bean.equals("")){
					String title = (i + 1) + ". " + bean.getTitle().replaceAll("<[/]?em>", ""), source = bean.getDomainSource(), pubdate = bean
							.getPubdate().toString(), summary = bean.getSummary().replaceAll("<[/]?em>", ""), href = bean.getUrl();
					String links;
					try {
						if(href.indexOf("https://")==-1){
							links = href.substring(href.indexOf("http://") + 7);
							links = links.substring(0, links.indexOf("/"));
						}else{
							links = href.substring(href.indexOf("https://") + 8);
							links = links.substring(0, links.indexOf("/"));
						}
					} catch (Exception e) {
						links = href;
					}
					html.append("<li>");
					html.append("<h3 class=\"title\"><a href=\"" + href + "\" target=\"_blank\">" + title + "</a></h3>");
					html.append("<div class=\"source\">【来源】" + source + "   " + pubdate + "</div>");
					html.append("<div class=\"links\">【链接】<a href=\"" + href + "\" target=\"_blank\">" + links + "</a></div>");
					html.append("<div class=\"summary\">【摘要】" + summary + "</div>");
					html.append("</li>");
					num++;
					if(num==10)
						break;
				}

			}
		}
		html.append("</ul>");
		html.append("</div>");
		return html.toString();
	}

}
